//订单查询
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            aShopInfo: {
                shops: [],
                shopTypes: [{
                    shopTypeId:'',
                    typeName:'全部'
                }],
                merchants:[],
                total: 0,
                records: 1,
                orderDetail: false,
                conditions: {
                    shopName: '',
                    shopType: '',
                    state: '',
                    appId: '',
                    merchantId:''
                }
            }
        },
        _initMethod: function () {
            $that._listShopTypes();
            $that._listMerchants();
            $that._listAShops(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {

            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listAShops(_currentPage, DEFAULT_ROWS);
            });
            vc.on('aShop', 'aShop', function () {
                $that._listAShops(DEFAULT_PAGE,DEFAULT_ROWS);
            });
        },
        methods: {
            _listAShops: function (_page, _rows) {
                $that.aShopInfo.conditions.page = _page;
                $that.aShopInfo.conditions.row = _rows;
                let param = {
                    params: $that.aShopInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/shop.queryShopsByAdmin',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.aShopInfo.total = _json.total;
                        $that.aShopInfo.records = _json.records;
                        $that.aShopInfo.shops = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.aShopInfo.records,
                            dataCount: $that.aShopInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            swatchShopType:function(_shopType){
                $that.aShopInfo.conditions.shopType = _shopType.shopTypeId;
                $that._listAShops(DEFAULT_PAGE,DEFAULT_ROWS);
            },
            _listShopTypes: function(_page, _rows) {

                let param = {
                    params: {
                        page:1,
                        row:100
                    }
                };
                let _shopTypes = [{
                    shopTypeId:'',
                    typeName:'全部'
                }]
                //发送get请求
                vc.http.apiGet('/shopType.queryShopType',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        _json.data.forEach(d => {
                            _shopTypes.push(d)
                        });
                        $that.aShopInfo.shopTypes = _shopTypes;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _queryOrdersMethod: function () {
                $that._listAShops(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openShopWithdrawModel: function(_shop){
                vc.emit('shopWithdraw','shopWithdrawModel', _shop);
            },
            _openOrderDetailModel: function (_order) {
                vc.emit('orderDetailManage', 'listOrderDetails', _order.cBusiness);
            },
            _listMerchants: function(_page, _rows) {
                let param = {
                    params: {
                        page:1,
                        row:100,
                        storeTypeCd: '800900000005'
                    }
                };
                //发送get请求
                vc.http.apiGet('/store.listStores',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                       
                        $that.aShopInfo.merchants = _json.data;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openShopDetail:function(_shop){
                window.open('/#/pages/shop/aShopDetail?shopId='+_shop.shopId);
            }
        }
    });
})(window.vc);
